﻿#include "Measure/MeasureData.h"
#include <QDebug>

void MeasurementData::clear()
{
    m_measure.clear();
}

void MeasurementData::buildData(int N)
{
    m_measure.clear();
    for(int i = 0; i < N; i++)
    {
        MeasurePair d;
        d.specID = i;
        m_measure.append(d);
    }
    m_current = 0;
}

void MeasurementData::setRecipeName(QString name, int id, QString description)
{
    m_recipeName = name;
    m_recipeID = id;
    m_description = description;
}

void MeasurementData::setPanelID(QString id)
{
    m_panelID = id;
}

MeasurementData::MeasurementData()
{
}
void MeasurementData::setLineName(QString lineName, int id)
{
    m_lineID = id;
    m_lineName = lineName;
}
void MeasurementData::append(MeasurePair d)
{
    m_measure.append(d);
}

void MeasurementData::setData(MeasurePair d)
{
    if(m_measure.isEmpty())
    {
        m_measure.append(d);
    }
    int N = m_measure.size();
    if(m_current >= 0 && m_current < N)
    {
        m_measure.replace(m_current, d);
    }
}

MeasurePair &MeasurementData::currentMeasure()
{
    return m_measure[m_current];
}

bool MeasurementData::next()
{
    int N = m_measure.size();
    if(m_current < N - 1)
    {
        m_current ++;
        return true;
    }
    return false;
}

bool MeasurementData::prev()
{
    int N = m_measure.size();
    if(N == 0)
    {
        return false; // 说明没有测量项，这时不能移动
    }
    if(m_current > 0 && m_current < N)
    {
        m_current --;
        return true;
    }
    return false;
}

bool MeasurementData::moveTo(int index)
{
    int N = m_measure.size();
    if( index >= 0 && index < N)
    {
        m_current = index;
        return true;
    }
    return false;
}
